<template>
	<view>
		<!-- 切换tab -->
		<view class="flexcenter mainpadding ffffff">
			<view class="flexcenter sanshis">
				<view :class="current==1?'focustext':'nofocustext'" @click="selectab(1)">课程</view>
			</view>
			<view class="flexcenter sanshis">
				<view :class="current==2?'focustext':'nofocustext'" @click="selectab(2)">场地</view>
			</view>
			<view class="flexcenter sanshis">
				<view :class="current==3?'focustext':'nofocustext'" @click="selectab(3)">赛事</view>
			</view>
			<view class="flexcenter sanshis">
				<view :class="current==4?'focustext':'nofocustext'" @click="selectab(4)">活动</view>
			</view>
		</view>
		<!-- 内容 -->
		<view class="flexcenter" v-if="!list.data.length">
			<view class="placeholderimage" style="margin-top: 300rpx;" ></view>
		</view>
		<view class="mainpadding2 ffffff margin_top1" v-if="list.data.length">
			<template v-if="current==1">
				<view class=" xiahuaxian shangc" v-for="item in list.data" :key="item.id">
					<view class="flexbetween">
						<view class="sanshier xiaohei fonweight yhxk">{{item.name}}</view>
						<view class="strongtext xiaohong nofonweight">待消费</view>
					</view>
					<view class="flextop margin_top2">
						<view class="shilitu">
							<image :src="item.image_text" mode=""></image>
						</view>
						<view class="" style="width: 69%;">
							<view class="ershiba xiaohui nofonweight">下单时间：{{item.createtime_text}}</view>
							<view class="flexbetween margin_top2">
								<view class="ershiba xiaohui nofonweight">实付：￥{{item.pay_price}}元
								<text v-if="Number(item.total_score)">+{{item.total_score}}分</text></view>
							</view>
							<view class="flexright">
								<view class="lvbtn margin_top1" @click="chaknjm(1,item.id)">查看券码 </view>
							</view>
						</view>
					</view>
				</view>
			</template>
			<template v-if="current==2">
				<view class=" xiahuaxian shangc" v-for="item in list.data" :key="item.id">
					<view class="flexbetween">
						<view class="sanshier xiaohei fonweight yhxk">{{item.name}}</view>
						<view class="strongtext xiaohong nofonweight">待消费</view>
					</view>
					<view class="flextop margin_top2">
						<view class="shilitu">
							<image :src="item.image_text" mode=""></image>
						</view>
						<view class="" style="width: 69%;">
							<view class="ershiba xiaohui nofonweight">下单时间：{{item.createtime_text}}</view>
							<view class="flexbetween margin_top2">
								<view class="ershiba xiaohui nofonweight">实付：￥{{item.pay_price}}元</view>
							</view>
							
						</view>
					</view>
					<view class="flexbetween margin_top2" v-for="ite in item.cgordercgb" :key="ite.id" @click="ckhxm(item,ite)">
						<view class=" flexcenter">
							<view class="margin_top2 " :class="ite.status==1?'chanbox':'chanboxs'">
								<view :class="ite.status==1?'shijbox':'shijboxs'">{{ite.sk_time_text}}-{{ite.end_time}}</view>
								<view class="" style="padding: 14rpx 0;">
									<view class="sanshier nofonweight xiaohei textcenter">￥{{ite.price}}</view>
								</view>
							</view>
						</view>
						<view class="flexright" v-if="ite.status==1" >
							<view class="lvbtn margin_top1">查看券码 </view>
						</view>
					</view>
				</view>
			</template>
			<template v-if="current==3">
				<view class=" xiahuaxian shangc" v-for="item in list.data" :key="item.id">
					<view class="flexbetween">
						<view class="sanshier xiaohei fonweight yhxk">{{item.ss.name}}</view>
						<view class="strongtext xiaohong nofonweight">待消费</view>
					</view>
					<view class="flextop margin_top2">
						<view class="shilitu">
							<image :src="item.ss.image_text" mode=""></image>
						</view>
						<view class="" style="width: 69%;">
							<view class="ershiba xiaohui nofonweight">下单时间：{{item.createtime_text}}</view>
							<view class="flexbetween margin_top2">
								<view class="ershiba xiaohui nofonweight">实付：￥{{item.ss.price}}元</view>
							</view>
							<view class="flexright">
								<view class="lvbtn margin_top1" @click="chaknjm(3,item.id)">查看券码 </view>
							</view>
						</view>
					</view>
				</view>
			</template>
			<template v-if="current==4">
				<view class=" xiahuaxian shangc" v-for="item in list.data" :key="item.id">
					<view class="flexbetween">
						<view class="sanshier xiaohei fonweight yhxk">{{item.activity.name}}</view>
						<view class="strongtext xiaohong nofonweight">待消费</view>
					</view>
					<view class="flextop margin_top2">
						<view class="shilitu">
							<image :src="item.activity.image_text" mode=""></image>
						</view>
						<view class="" style="width: 69%;">
							<view class="ershiba xiaohui nofonweight">下单时间：{{item.createtime_text}}</view>
							<view class="flexbetween margin_top2">
								<view class="ershiba xiaohui nofonweight">实付：￥{{item.activity.price}}元</view>
							</view>
							<view class="flexright">
								<view class="lvbtn margin_top1" @click="chaknjm(4,item.id)">查看券码 </view>
							</view>
						</view>
					</view>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				current: 1,//1课程，2场地，3赛事，4活动
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			ckhxm(current,item){
				if(item.status!=1){
					httpRequest.toast("当前状态无法操作")
					return false
				}
				uni.navigateTo({
					url:"/pages_homepage/chakanjuanm?type=2&id="+current.id+"&child_id="+item.id
				})
			},
			init(isPage, page) {
				let _this = this;
				let data = {
					page: page || 1,
					limit: _this.limit,
					status:2
				}
				let url = '/api/user/kcOrderIndex'
				if(this.current==2){
					url = '/api/user/cgOrderIndex'
				}
				if(this.current==3){
					url = '/api/user/ssBmIndex'
					this.$set(data,"hx_status",1)
					delete data.status
				}
				if(this.current==4){
					url = '/api/user/activityBmIndex'
					this.$set(data,"hx_status",1)
					delete data.status
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			chaknjm(val,id) {
				uni.navigateTo({
					url: '/pages_homepage/chakanjuanm?type='+val+"&id="+id
				})
			},
			selectab(i) {
				if (i == this.current) {
					return false
				}
				this.current = i
				this.list.data = []
				this.init()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.lvbtn {
		font-size: 24rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		padding: 10rpx 30rpx;
		background: #1BA95B;
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.touxiang {
		width: 40rpx;
		height: 40rpx;
		border-radius: 50%;

		image {
			border-radius: 50%;
			width: 100%;
			height: 100%;
		}
	}

	.shangc1 {
		padding-top: 30rpx;
	}

	.shangc1:first-child {
		padding-top: 0rpx;
	}


	.shangc {
		padding-top: 30rpx;
	}

	.shilitu {
		width: 200rpx;
		height: 160rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	page {
		background: #F9F9F9;
	}

	.wushi {
		width: 50%;
	}

	.focustext {
		font-size: 30rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #1BA95B;
	}

	.nofocustext {
		font-size: 30rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #000000;
	}
	.chanbox {
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid #1BA95B;
		// width: 260rpx;
	}
	.chanboxs{
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		border: 2rpx solid #ebebeb;
	}
	.shijboxs {
		padding: 12rpx 20rpx;
		background: #ebebeb;
		font-size: 26rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #333;
	}
	.shijbox {
		padding: 12rpx 20rpx;
		background: #1BA95B;
		font-size: 26rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
	}
</style>